var t, a = require("../../../../@babel/runtime/helpers/interopRequireDefault"), e = require("../../../../@babel/runtime/helpers/toConsumableArray"), s = a(require("../../../../@babel/runtime/regenerator")), i = require("../../../../@babel/runtime/helpers/defineProperty"), o = require("../../../../@babel/runtime/helpers/asyncToGenerator"), r = 1, n = getApp();

Page({
    data: {
        istypeclass: !1,
        inputs: "",
        amout: !1,
        loading: !1,
        allLoaded: !0,
        goload: !1,
        goods: [],
        order_by: "",
        order_field: "",
        showGoodScreen: !1,
        brandId: "",
        filterId: [],
        classifyBol: !0,
        zoneId: "",
        coupon: "",
        showcccc: !1,
        activeName: "1",
        plugin_id: 0,
        btnFlag: !1,
        btnData: {
            button_size: 40,
            over_top: 500,
            position_location: "right",
            icon_url: ""
        },
        machineId: "",
        showHistory: !1,
        deliverId: null,
        point: {},
        requestLoading: !0,
        searchScreen: {}
    },
    onLoad: (t = o(s.default.mark(function t(a) {
        var e, o, r, n, d, c, h;
        return s.default.wrap(function(t) {
            for (;;) switch (t.prev = t.next) {
              case 0:
                "" == a.id || isNaN(a.id) || (this.setData((i(e = {}, "searchScreen.typestring", a.id), 
                i(e, "istypeclass", !0), e)), wx.setNavigationBarTitle({
                    title: "分类列表"
                })), console.log(a.kind);
                try {
                    (o = wx.getStorageSync("zoneId")) && this.setData({
                        zoneId: o
                    });
                } catch (t) {}
                if (a.fromPage && this.setData({
                    fromPage: a.fromPage
                }), a.kind && this.setData({
                    kind: "kind"
                }), a.keyword && this.setData({
                    inputs: a.keyword
                }), a.order_field && this.setData({
                    order_field: a.order_field
                }), a.order_by && this.setData({
                    order_by: a.order_by
                }), a.coupon && this.setData({
                    coupon: a.coupon
                }), a.as_id && this.setData({
                    zoneId: a.as_id
                }), a.brand_id && this.setData(i({}, "searchScreen.brandId", a.brand_id)), 1 == a.plugin_id && this.setData({
                    plugin_id: a.plugin_id
                }), a.machineId && this.setData({
                    machineId: a.machineId
                }), !a.product_attr) {
                    t.next = 30;
                    break;
                }
                r = a.product_attr.split(","), n = this.data.attr ? this.data.attr : [], d = 0;

              case 17:
                if (!(d < r.length)) {
                    t.next = 29;
                    break;
                }
                c = 0;

              case 19:
                if (!(c < n.length)) {
                    t.next = 26;
                    break;
                }
                if (n[c].rot != r[d]) {
                    t.next = 23;
                    break;
                }
                return this.setData(i({}, "attr[" + c + "].show", !1)), t.abrupt("break", 26);

              case 23:
                c++, t.next = 19;
                break;

              case 26:
                d++, t.next = 17;
                break;

              case 29:
                this.setData({
                    attrStr: r
                });

              case 30:
                if (a.filtering && (h = (h = a.filtering.split(",")).map(function(t) {
                    return parseInt(t);
                }), this.setData(i({}, "searchScreen.filterId", isNaN(h) ? void 0 : h))), a.category && this.setData(i({}, "searchScreen.typestring", a.category)), 
                a.classificationParentIndex && this.setData({
                    classificationParentIndex: parseInt(a.classificationParentIndex),
                    activeName: parseInt(a.classificationParentIndex)
                }), a.classificationId1 && this.setData({
                    classificationId1: parseInt(a.classificationId1)
                }), a.classificationId2 && this.setData({
                    classificationId2: parseInt(a.classificationId2)
                }), !a.tmpl || "dy" != a.tmpl) {
                    t.next = 38;
                    break;
                }
                return t.next = 38, this.getNowPackageDeliver();

              case 38:
                this.search();

              case 39:
              case "end":
                return t.stop();
            }
        }, t, this);
    })), function(a) {
        return t.apply(this, arguments);
    }),
    tapUpper: function() {
        try {
            wx.navigateBack({
                delta: 1,
                success: function(t) {},
                fail: function(t) {
                    wx.reLaunch({
                        url: "/packageG/index/index"
                    });
                },
                complete: function(t) {}
            });
        } catch (t) {
            wx.reLaunch({
                url: "/packageG/index/index"
            });
        }
    },
    onReady: function() {},
    onShow: function() {
        this.data.deliverId && this.getNowPackageDeliver();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (!this.data.allLoaded) {
            r++;
            this.gotoSearch(r, !0);
        }
    },
    onShareAppMessage: function() {
        var t = "";
        return t += "?keyword=" + this.data.inputs, t += "&order_field=" + this.data.order_field, 
        t += "&order_by=" + this.data.order_by, t += "&coupon=" + this.data.coupon, t += "&as_id=" + this.data.zoneId, 
        t += "&brand_id=" + this.data.searchScreen.brandId, t += "&product_attr=" + this.data.searchScreen.attrstr, 
        t += "&filtering=" + this.data.searchScreen.filterId, t += "&category=" + this.data.searchScreen.typestring, 
        t += "&classificationParentIndex=" + this.data.classificationParentIndex, t += "&classificationId1=" + this.data.classificationId1, 
        t += "&classificationId2=" + this.data.classificationId2, console.log(t), {
            path: "/packageB/member/category/search_v2/search_v2" + t
        };
    },
    onPageScroll: function(t) {
        t.scrollTop > 80 ? this.data.btnFlag || this.setData({
            btnFlag: !0
        }) : this.data.btnFlag && this.setData({
            btnFlag: !1
        });
    },
    sortOut: function(t) {
        console.log(t);
        var a = t.detail, e = a.order_by, s = a.order_field;
        this.setData({
            order_by: e,
            order_field: s
        }), 0 != this.data.goods.length && (r = 1, this.setData({
            goods: []
        }), this.gotoSearch(r));
    },
    search: function() {
        r = 1, this.setData({
            goods: [],
            goload: !0
        }), wx.showLoading({
            title: "加载中",
            mask: !0
        }), this.gotoSearch(r);
    },
    serachTag: function(t) {
        var a = t.detail;
        this.setData({
            inputs: a
        }), this.search();
    },
    gotoSearch: function() {
        var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 1, a = arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
        this.selectComponent("#search_history").appendKeywords(this.data.inputs);
        var s, i = this, o = "";
        o = "1" == this.data.fromPage ? n.getNetAddresss("plugin.pending-order.frontend.wholesale-area.goods-list") : this.options.tmpl && "dy" == this.options.tmpl ? n.getNetAddresss("plugin.supplier.frontend.category.search-goods") : this.options.CommodityRights && "CommodityRights" == this.options.CommodityRights ? n.getNetAddresss("plugin.love-speed-pool.frontend.goods.getList") : this.data.machineId ? n.getNetAddresss("plugin.automat.frontend.goods.searchGoods") : n.getNetAddresss("goods.goods.search-goods"), 
        (this.data.searchScreen.top || this.data.searchScreen.mini) && (s = this.data.searchScreen.mini ? "".concat(this.data.searchScreen.mini).concat(this.data.searchScreen.top ? "," + this.data.searchScreen.top : this.data.searchScreen.top ? this.data.searchScreen.top : "") : this.data.searchScreen.top), 
        o += "&search[keyword]=" + this.data.inputs, o += "&page=" + t, o += "&order_field=" + this.data.order_field, 
        o += "&order_by=" + this.data.order_by, o += "&search[couponid]=" + this.data.coupon, 
        o += "&search[as_id]=" + this.data.zoneId, o += "&search[brand_id]=" + this.data.searchScreen.brandId, 
        o += "&search[product_attr]=" + this.data.searchScreen.attrstr, o += "&search[filtering]=" + this.data.searchScreen.filterId, 
        o += "&search[category]=" + this.data.searchScreen.typestring, s && (o += "&search[price_range]=" + s), 
        1 == this.data.plugin_id && (o += "&search[plugin_id]=0"), this.data.machineId && (o += "&automat_machine_id=" + this.data.machineId + "&search[automat_machine_id]=" + this.data.machineId), 
        this.setData({
            requestLoading: !0
        }), n._getNetWork({
            showToastIn: !1,
            url: o,
            success: function(t) {
                var s = t.data;
                if (1 == s.result) {
                    if (i.setData({
                        loading: !1,
                        allLoaded: !1
                    }), s.data.data.length <= 0) return void i.setData({
                        loading: !0,
                        allLoaded: !0
                    });
                    if (s.data.current_page > s.data.last_page) return void i.setData({
                        loading: !0,
                        allLoaded: !0
                    });
                    var o = i.data.goods;
                    o.push.apply(o, e(s.data.data));
                    for (var r = 0; r < o.length; r++) parseInt(Number(0 == o[r].market_price)) ? o[r].notMarket_price = 0 : o[r].notMarket_price = 1;
                    i.setData({
                        goods: o,
                        requestLoading: !1
                    });
                    try {
                        i.setData({
                            goods_template: s.data.goods_template,
                            goods_style_set: s.data.goods_style_set
                        });
                    } catch (t) {
                        console.log(t);
                    }
                    if (a || !i.data.goods_template || "02" != i.data.goods_template.names && "03" != i.data.goods_template.names || i.setData({
                        showcccc: !0,
                        classifyBol: !1
                    }), s.data.data.length < 15) return void i.setData({
                        loading: !0,
                        allLoaded: !0
                    });
                } else i.setData({
                    requestLoading: !1
                });
            },
            fail: function(t) {},
            complete: function() {
                wx.hideLoading();
            }
        });
    },
    classifyBolbtn: function() {
        this.data.showcccc ? this.setData({
            showcccc: !1,
            classifyBol: !0
        }) : this.setData({
            showcccc: !0,
            classifyBol: !1
        });
    },
    inpbtn: function(t) {
        var a = t.detail.value;
        this.setData({
            inputs: a
        });
    },
    inpbtnclear: function() {
        this.setData({
            inputs: ""
        });
    },
    showbox: function() {
        this.setData({
            showGoodScreen: !this.data.showGoodScreen
        });
    },
    focusSearchInput: function() {
        this.setData({
            showHistory: !0
        });
    },
    blurSerachInput: function() {
        this.setData({
            showHistory: !1
        });
    },
    searchBlur: function() {
        this.setData({
            showHistory: !1
        });
    },
    searchfocus: function() {
        this.setData({
            showHistory: !0
        });
    },
    getNowPackageDeliver: function() {
        var t = this;
        return o(s.default.mark(function a() {
            var e;
            return s.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    e = null;
                    try {
                        e = wx.getStorageSync("deliverId");
                    } catch (t) {}
                    if (!e) {
                        a.next = 7;
                        break;
                    }
                    return t.data.deliverId && t.data.deliverId != e && (t.data.deliverId = e, t.search()), 
                    a.abrupt("return", !0);

                  case 7:
                    if (t.options.dyID) {
                        a.next = 10;
                        break;
                    }
                    return a.next = 10, t._asyncLocation();

                  case 10:
                    return wx.showLoading({
                        title: "加载中",
                        mask: !0
                    }), a.abrupt("return", new Promise(function(a, e) {
                        var s = {};
                        t.data.point && t.data.point.lng && (s = {
                            lng: t.data.point.lng || "",
                            lat: t.data.point.lat || ""
                        }), t.options.dyID && (s.deliver_id = t.options.dyID);
                        var i = n.getNetAddresss("plugin.package-deliver.frontend.decorate-deliver.getNowPackageDeliver");
                        n._postNetWork({
                            url: i,
                            data: s,
                            success: function(s) {
                                wx.hideLoading();
                                var i = s.data;
                                1 == i.result ? (t.data.deliverId = i.data.id, wx.setStorageSync("deliverId", i.data.id), 
                                a()) : (wx.showToast({
                                    title: i.msg,
                                    duration: 1e3,
                                    icon: "none"
                                }), e());
                            },
                            fail: function(t) {
                                wx.hideLoading(), console.log(t.msg);
                            }
                        });
                    }));

                  case 12:
                  case "end":
                    return a.stop();
                }
            }, a);
        }))();
    },
    _asyncLocation: function() {
        var t = this;
        return new Promise(function(a, e) {
            t._getLocation(function(e, s) {
                var i = n.qqMapTransBMap(parseFloat(s.lng), parseFloat(s.lat));
                t.data.point = i, a();
            });
        });
    },
    confirmGoodScreen: function(t) {
        this.setData({
            goods: [],
            goload: !0,
            searchScreen: t.detail
        }), this.cloneGoodScreen(), this.gotoSearch();
    },
    cloneGoodScreen: function() {
        this.setData({
            showGoodScreen: !1
        });
    }
});